home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * ProfilesManagerDlg.js
- *
- * USAGE
- * Part of Netobjects JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2005 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
-
- if (!IS.isModuleInitialized("IS.NOF.UI.ProfilesManagerDlg"))
- {
-
- /****h* NOF_JavaScript_Library/NOF.UI.ProfilesManagerDlg
- *
- * NAME
- * NOF.UI.ProfilesManagerDlg
- *
- * DESCRIPTION
- *
- * External dependencies: NOF.UI.ListEditorDlg, NOF.UTIL.Validator, NOF.Contract,
- * NOF.DIALOGS.Messages, NOF.TEXT.MessageFormat, NOF.WindowEvent
- ****/
- function NOF_ProfilesManager_Dialog( _editedElem, _document, _name ) {
- this.__proto__ = NOF_ProfilesManager_Dialog.prototype;
-
- if ( arguments.length == 0 )
- this.SUPER();
- else{
- this.SUPER( _editedElem, _document, _name );
- this.validator = new NOF.UTIL.Validator();
- this.validator.setIsAlphaNum(true);
- }
- }
-
- NOF_ProfilesManager_Dialog.inherits( NOF.UI.ListEditorDlg );
- function NOF_ProfilesManager_Dialog_ProtoBuilder(){
-
- var member = NOF_ProfilesManager_Dialog.prototype;
- member.defaultName = "GENERIC_PROFILE_DIALOG";
- member.maxCharsDisplayedNo = 40;
-
- var method = NOF_ProfilesManager_Dialog.prototype;
-
- method.onLoad = function onLoad() {
- this.doc.initialize( this );
- this.initFieldPropertyValues();
- this.setTitle( this.getResourceProperty( "profiles.label.title" ) );
-
- this.getEditedElement().load();//make sure the object is loaded
- var profiles = this.getEditedElement().getListElements();
-
- if (profiles.length > 0){
- var sMore = this.getResourceProperty( "label.longname.more" );
- var profilesList = new Array(profiles.length);
- for (var i=0; i<profiles.length; i++) {
- var pName = profiles[i].name;
- NOF.Contract.Assert( pName !=null && pName.length > 0, "profile name cannot be null");
- if ( pName.length > this.maxCharsDisplayedNo ){
- pName = pName.substring( 0, this.maxCharsDisplayedNo - sMore.length ) + sMore;
- }
-
- profilesList[i] = [pName, profiles[i].id];
- }
-
- this.doc.setElementItems('form.select.list', profilesList);
- }
-
- this.onEnableRemoveButton( false );
- this.onEnableOkButton( false );
- this.doc.focusElement( "profiles.text.name" );
- }
-
- method.onEnableRemoveButton = function onEnableRemoveButton( state ){
- if (state)
- this.doc.enableElement( "profiles.button.remove" );
- else
- this.doc.disableElement( "profiles.button.remove" );
- }
-
- method.onEnableOkButton = function onEnableOkButton( state ){
- if (state)
- this.doc.enableElement( "profiles.button.ok" );
- else
- this.doc.disableElement( "profiles.button.ok" );
- }
-
- method.getMaxCharsDisplayedNo = function getMaxCharsDisplayedNo(){
- return this.maxCharsDisplayedNo;
- }
-
- method.setMaxCharsDisplayedNo = function setMaxCharsDisplayedNo(charsNo){
- this.maxCharsDisplayedNo = charsNo;
- }
-
- method.onOk = function onOk() {
- var profList = this.getEditedElement().getListElements();
- var pName = this.doc.getElementValue( "profiles.text.name" );
- for ( i = 0; i < profList.length; i++ ) {
- /*TODO: think this to accomodate also the case when a default exists and want to protect it
- if ( this.doc.getElementValue( "profiles.text.name" ) == "default" ) {
- alert( this.getResourceProperty( "profiles.label.defaultexists" ))
- this.doc.setElementValue( "profiles.text.name", "" );
-
- return false;
- }
- */
-
- if ( pName == profList[i].name ){
- var msg = NOF.TEXT.MessageFormat.format(this.getResourceProperty( "profiles.label.alreadyexists" ), pName);
-
- //if ( ! showwarning( msg ) ) {
- if ( ! NOF.DIALOGS.Messages.warning(msg, null, null, "", this.getResourceProperty( "label.yes"), this.getResourceProperty( "label.no"), this.doc.getRawDoc().parentWindow, 300, 90) ) {
- this.doc.focusElement( "profiles.text.name" );
- return false;
- }
- }
- }
-
- //make sure we get the latest value from controls
- this.getApp().dispatchEvent(new NOF.WindowEvent( "UpdateData", true));
-
- var newProfile = this.getEditedElement().getNewElement();
- newProfile.verifyDoc();
- this.setProfileData( newProfile );
- newProfile.saveConfigFile( this.doc.getElementValue( "profiles.text.name" ) );
-
- this.getWindowHandle().close();
- }
-
- method.setPofileData = function setPofileData( profile ){
- NOF.Contract.Assert("setPofileData is an abstract method!");
- }
-
- method.onRemove = function onRemove() {
- //debugger;
- var toRemove = this.doc.getElementValue('form.select.list');
-
- this.getEditedElement().remove( toRemove );
- this.doc.removeElements('form.select.list', toRemove);
- this.editedElement.setListElements ( this.doc.getElementItems('form.select.list') );
-
- var idx = this.doc.getElementItems('form.select.list').length;
- if (idx == 0)
- this.onEnableRemoveButton( false );
- }
-
- method.onKeyUp = function onKeyUp(source, window) {
- if (window.event.keyCode == 8 || window.event.keyCode == 46)
- if (source.value.length == 0)
- this.onEnableOkButton( false );
-
- return true;
- }
-
- method.onKeyDown = function onKeyDown(source, window) {
- var chr = String.fromCharCode(window.event.keyCode);
- var res = this.validator.validateInput(chr, source.value);
-
- if (source.value.length == 0 && res)
- this.onEnableOkButton( true );
-
- return res;
- }
-
- method.onSelect = function onSelect() {
- this.onEnableRemoveButton( true );
- }
-
-
- method.initFieldPropertyValues = function initFieldPropertyValues () {
- var fieldPropertyValue = new Array();
-
- fieldPropertyValue['form.text.label'] = 'profiles.text.name';
- fieldPropertyValue['form.select.list'] = 'profiles.select.list';
- fieldPropertyValue['form.button.ok'] = 'profiles.button.ok';
- fieldPropertyValue['form.button.remove'] = 'profiles.button.remove';
-
- this.doc.setPropertyMap(fieldPropertyValue);
- }
- }
-
- NOF_ProfilesManager_Dialog_ProtoBuilder();
- UI.__proto__.ProfilesManagerDlg = NOF_ProfilesManager_Dialog;
- }